package com.noahplat.datapro.mapper;

import com.noahplat.datapro.pojo.Site;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @InterfaceName: SiteProMapper
 * @Description: 可穿戴设备位置数据mapper
 * @Author 李景星
 * @Date 2021/3/4
 * @Version 1.0
 */
public interface SiteProMapper extends Mapper<Site> {

    /**
     * 查询设备当前位置坐标
     * @param imei
     * @return
     */
    @Select("select LAST_ROW(site) as site, ts as ts from site_${imei}")
    public Site getNowSite(@Param("imei") String imei);

    /**
     * 获取设备历史位置
     * @param imei
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("select site as site, ts as ts from site_${imei} where ts >= #{startDate} and ts < #{endDate} order by ts desc")
    public List<Site> getHisSite(@Param("imei") String imei, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    /**
     * 工地项目当前位置坐标
     * @param list
     * @return
     */
    @Select("<script>select imei as imei, LAST(site) as site, ts as ts from site where imei in(<foreach collection = 'list' item='String' separator=','>#{String}</foreach>) group by imei</script>")
    public List<Site> selectSite(@Param("list") List<String> list);
}
